﻿using System;
using System.ComponentModel;
using System.Windows;

namespace CodeAngel.UI.Extensions
{
    public static class PropertyValueChangedExtensions
    {

        /// <summary>
        /// Adds an event handler that will be called when the value a particular property of a dependency 
        /// object has changed.
        /// </summary>
        /// <param name="dependencyObject">The dependecy object to listen for a property value change.</param>
        /// <param name="dependencyProperty">The dependency property to listen for a value change.</param>
        /// <param name="eventHandler">The event handler that will be called when the value of the property changes.</param>
        public static void AddValueChanged(this DependencyObject dependencyObject, DependencyProperty dependencyProperty, EventHandler eventHandler)
        {
            var dpd = DependencyPropertyDescriptor.FromProperty(dependencyProperty, dependencyObject.GetType());
            dpd.AddValueChanged(dependencyObject, eventHandler);
        }

    }
}
